﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TV4Home.Server.TVEInteractionLibrary;
using TV4Home.Server.TVEInteractionLibrary.Interfaces;
using TV4Home.WebInterface.UI.Code;

namespace TV4Home.WebInterface.UI
{
    public partial class ProgramShortInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(Request["id"]))
                return;

            UpdateUI();
        }

        private void UpdateUI()
        {
            try
            {
                ShowProgramShortInfo();
            }
            catch (Exception ex)
            {
                this.lblError.Text = ex.Message;

                this.pnContent.Visible = false;
                this.pnError.Visible = true;
            }
        }

        private void ShowProgramShortInfo()
        {
            int id = Int32.Parse(Request["id"]);

            if (id == 0)
                throw new ArgumentException("The specified ID is not valid!");

            WebProgramBasic program = WebService.TV4HomeWebService.ServiceInstance.GetProgramBasicById(id);

            // insert values
            this.lblTitle.Text = program.Title;
            this.lblTime.Text = String.Format("{0}, {1} - {2}", program.StartTime.Date.ToLongDateString(), program.StartTime.ToShortTimeString(), program.EndTime.ToShortTimeString());
            this.lblDuration.Text = (program.EndTime - program.StartTime).ToPrettyString();

            this.lblDescription.Text = program.Description.Replace("\n", "<br/>");
        }
    }
}
